//plugin jquery.cookies
jQuery.cookie = function (name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
if(typeof ucenter_domain=="undefined") ucenter_domain="http://passport.zhulong.com/";
// JavaScript Document
$(document).ready(function(){
	/*用户名hover*/
	$("#mylname").mouseover(function(){
		$("#mylname_menu").show();
	}).mouseout(function(){
		$("#mylname_menu").hide();
	});
	/*导航hover*/
	$("#daohang").mouseover(function(){
		$("#mymap_menu").show();
	}).mouseout(function(){
		$("#mymap_menu").hide();
	});
	$('.zhul_ad_a .zhul_ad_img1').eq(2).addClass('zhul_ad_active');
	$('.zhul_ad_a').mouseover(function(){
		if($(this).find(".zhul_ad_img1").hasClass("zhul_ad_active")){
			return;
		}else{
			$(".zhul_ad_img1").removeClass("zhul_ad_active");
			$(this).find(".zhul_ad_img1").addClass("zhul_ad_active")
		}
		
	}).mouseout(function(){
		
	});
	$("a").live("click",function(e){
		var href=$(this).attr("href");
		if(href.indexOf("user/logout")>-1){
			$.getJSON(ucenter_domain+"/user/logout?callback=?",{},function(){
				window.location.href=window.location.href;
			});
			return false;
		}
	});
});
function kfocus(obj)
{
	if(isInitKey(obj.value)){
		obj.defaultValue=obj.value;
		if(obj.value==obj.defaultValue)
		{
			obj.value='';
			obj.style.color='#000'
		}
	}
}
;(function (){
	$("#loginurl").attr("href","http://passport.zhulong.com/user/login?redirecturl="+document.URL); 
 	var ZLID = jQuery.cookie("ZLID");
    var username = jQuery.cookie("username");
    //console.log(ZLID+" "+username);
    if (ZLID && typeof username!="undefined" && username!=null && username!="")
	{
        $(".zhul_header_nologin").hide();
        $("#username").html(username+"<img src=\"/img/pubimg/bbs_jiao.png\"/>");
		var uid=jQuery.cookie("uid");
		$("#username").attr('href','http://passport.zhulong.com/archive');
		$("#userindex").attr('href','http://passport.zhulong.com/archive');
        $("#zhul_header_login").show();
    }
	else
	{
		$(".zhul_header_edu_nologin").show();
		$("#logout").hide();
	}

	//个人中心更多信息展示
	//console.log($("#user-login"));
	$(".user-info").hover(function(){
		$("#mylname_menu").show();
	},function(){
		$("#mylname_menu").hide();
	});

	/*消息hover*/
	$("#mymassage").mouseover(function(){
		$("#mymessage_menu").show();
	}).mouseout(function(){
		$("#mymessage_menu").hide();
	});
})();

